package com.example.springcloud.rocketmq.service;

import com.example.springcloud.rocketmq.channel.produce.ProduceSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.util.MimeTypeUtils;

/**
 * <pre>
 *      SendService
 * </pre>
 *
 * <pre>
 * @author mazq
 * 修改记录
 *    修改后版本:     修改人：  修改日期: 2021/03/16 11:01  修改内容:
 * </pre>
 */
@Service
@Slf4j
public class SendService {

    @Autowired
    private ProduceSource produceSource;

    public <T> void send(T msg , String tag) {
        Message message = MessageBuilder.withPayload(msg)
                .setHeader(RocketMQHeaders.TAGS , tag)
                .setHeader(MessageHeaders.CONTENT_TYPE , MimeTypeUtils.APPLICATION_JSON)
                .build();
        produceSource.output1().send(message);
    }


}
